#!/usr/bin/env python
#coding: utf-8
'''
Created on 2017年4月17日

@author: Administrator
'''
from common.models.abstract import TimeModel, StateModel
from django.contrib.auth.models import User
from django.db import models
from article import settings


class Article(TimeModel, StateModel):
    topic = models.CharField(default="", max_length=524, verbose_name="标题")
    content = models.TextField(default="", verbose_name="内容")
    user = models.ForeignKey(User, verbose_name="用户")
    text_content = models.TextField(default="", verbose_name="text内容")
    source = models.IntegerField(default=0, choices=settings.SOURCE_CHOICES, db_index=True, verbose_name=u'来源')
    source_id = models.BigIntegerField(default=0, verbose_name="来源id")

    class Meta:
        app_label = "article"
        verbose_name = u"文章"
        verbose_name_plural = u"文章"
        ordering = ["-id"]
        unique_together = ("source", "source_id")
    @property
    def source_url(self):
        return "%s%s/" % (settings.SOURCE_URL_CHOICES[self.source][1], self.source_id)
                          
